package org.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.web.domain.PageBean;
import org.web.domain.XinWen;
import org.web.service.WenZhangService;

import javax.annotation.Resource;
import javax.naming.Name;
import javax.servlet.http.HttpServletRequest;
import javax.xml.crypto.Data;
import java.util.Date;
import java.util.List;

/**
 * @Author:芯古子
 * @Date:2022/4/19 11:11
 **/
@Controller
public class YeServerlet {
    @Resource(name = "wenZhangService")
    private  WenZhangService service;
    @ResponseBody
    @RequestMapping("Ye")
    public PageBean<XinWen> ye(Integer classid,HttpServletRequest request){
        String currentPageStr = request.getParameter("currentPage");
        String PageSizeStr = request.getParameter("PageSize");
        String keyword = request.getParameter("keyword");
        if(keyword.equals("")){
            keyword=null;
        }
        int currentPage=0;
        //当前页面，如果前端没有给值给后端的话，默认当前页码是1
        if(currentPageStr!=null&&currentPageStr.length()>0){
            currentPage = Integer.parseInt(currentPageStr);
        }else {
            currentPage=1;
        }

        int PageSize=0;
        //页码，每页显示条数，如果没有赋值给后端，默认每页展示条数是5
        if(PageSizeStr!=null&&PageSizeStr.length()>0){
            PageSize = Integer.parseInt(PageSizeStr);
        }else {
            PageSize=3;
        }
        //3.调用service，去查询Pagebean对象
        PageBean<XinWen> pageBean = service.pageQuery(currentPage, PageSize,classid,keyword);
        //4.序列化返回的数据给前端
        return pageBean;
    }
    @ResponseBody
    @RequestMapping("order")
    public List<XinWen> pai(){
        List<XinWen> pai = service.pai();
        return pai;
    }
    @ResponseBody
    @RequestMapping("re")
    public List<XinWen> pai2(){
        List<XinWen> pai = service.pai2();
        return pai;
    }
}
